﻿using EntityModels.E01.Systems;
using EntityModels.E02.Identities;
using EntityModels.E03.Photographs;
using EntityModels.E04.Interactions;
using EntityModels.E05.Reports;
using EntityModels.E06.Socializes;
using EntityModels.E07.Chats;
using EntityModels.E08.Statistics;
using EntityModels.E09.Files;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System.Reflection.Emit;

namespace ORM
{
    public class PSPDbContext : IdentityDbContext<AppUser, AppRole, Guid>
    {
        public PSPDbContext(DbContextOptions options) : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            // 遍历所有实体类型，找到所有外键并关闭级联删除
            foreach (var entityType in builder.Model.GetEntityTypes())
            {
                // 找到实体的所有外键
                var foreignKeys = entityType.GetForeignKeys();

                foreach (var foreignKey in foreignKeys)
                {
                    // 设置删除行为为 Restrict 或 NoAction，关闭级联删除
                    foreignKey.DeleteBehavior = DeleteBehavior.Restrict;
                }
            }
            base.OnModelCreating(builder);

            builder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
            builder.EnableSoftDeletionGlobalFilter();
        }

        public DbSet<FileHash> FileHashs { get; set; }
        public DbSet<FilePath> FilePaths { get; set; }
        public DbSet<Notification> Notifications { get; set; }
        public DbSet<WeChatUser> WeChatUsers { get; set; }
        public DbSet<PhotographType> PhotographTypes { get; set; }
        public DbSet<Photograph> Photographs { get; set; }
        public DbSet<Like> Likes { get; set; }
        public DbSet<Star> Stars { get; set; }
        public DbSet<StarItem> StarItems { get; set; }
        public DbSet<UserWatch> UserWatchs { get; set; }
        public DbSet<Comment> Comments { get; set; }
        public DbSet<ReportType> ReportTypes { get; set; }
        public DbSet<Report> Reports { get; set; }
        public DbSet<Follow> Follows { get; set; }
        public DbSet<Conversation> Conversations { get; set; }
        public DbSet<Message> Messages { get; set; }
        public DbSet<PhotographStatistics> PhotographStatistics { get; set; }
        public DbSet<CommentReport> CommentReports { get; set; }

    }
}
